using ASP;
using HoWave.Common;
using HoWave.Web;
using HoWave.Web.Shop.Member;
using System;
using System.Data;
using System.Web.Profile;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
public class Member_Shop_OpenShop : Member, IRequiresSessionState
{
	protected ScriptManager ScriptManager1;
	protected Literal openshopReMe;
	protected HyperLink go_identify;
	protected Panel aplay_open_shop;
	protected TextBox TxtShopName;
	protected DropDownList DropShopClass;
	protected TextBox TxtOperatorItem;
	protected Shop_UserControls_HowaveProvinceCity ProvinceCity;
	protected Label Err_Address;
	protected TextBox txtAddress;
	protected Button ButSaveNewShop;
	protected PlaceHolder open_shop;
	protected DefaultProfile Profile
	{
		get
		{
			return (DefaultProfile)this.Context.Profile;
		}
	}
	protected global_asax ApplicationInstance
	{
		get
		{
			return (global_asax)this.Context.ApplicationInstance;
		}
	}
	protected void Page_Load(object sender, EventArgs e)
	{
		if (base.user.ShopID > 0)
		{
			this.WriteErrMsg(Language.GetMemberMsg("Common/YouQing", new string[0]), Language.Get("Shop/OpenShop/ShopExists"), "Index.aspx?mainurl=../Manage/shop_setup.aspx");
		}
		if (!base.user.CheckGroupPower("allowopenshop"))
		{
			this.WriteErrMsg("", Language.Get("Shop/OpenShop/NotAllowOpen"), "Index.aspx?mainurl=MyShop.aspx");
		}
		if (this.conn.ExecuteCount("Select count(UserInfoID) From HL_UserInfo Where UserID=" + base.user.UserID) == 0)
		{
			this.WriteErrMsg(Language.GetMemberMsg("Common/ZhuoQing", new string[0]), Language.Get("Shop/OpenShop/UserInfoErr"), "Index.aspx?mainurl=Shop_UserInfoList.aspx");
		}
		string a = base.user.UserInforRes["AuthenticationType"].ToString();
		if (a != "1")
		{
			this.WriteErrMsg(Language.GetMemberMsg("Common/ZhuoQing", new string[0]), "该用户还没有申请认证或让认证没有通过！", "Index.aspx?mainurl=Shop_Identify.aspx");
		}
		if (!base.IsPostBack)
		{
			this.open_shop.Visible = true;
			this.BindShopClass();
			this.ProvinceCity.SelectedProvince = base.user.UserInforRes["Province"].ToString();
			this.ProvinceCity.SelectedCity = base.user.UserInforRes["City"].ToString();
			this.ProvinceCity.SelectedArea = base.user.UserInforRes["CMArea"].ToString();
			this.txtAddress.Text = base.user.UserInforRes["Address"].ToString();
		}
	}
	protected void BindShopClass()
	{
		Shop_Class shop_Class = new Shop_Class(this.conn);
		this.DropShopClass.DataSource = shop_Class.GetRootClass();
		this.DropShopClass.DataBind();
	}
	protected void ButSaveNewShop_Click(object sender, EventArgs e)
	{
		string text = this.TxtShopName.Text;
		if (text.Length > 50)
		{
			this.Page.ClientScript.RegisterStartupScript(base.GetType(), "Test", "<script>alert('店铺名的长度不能超过50个字!');</script>");
		}
		else
		{
			int num = Convert.ToInt32(this.DropShopClass.SelectedValue);
			string text2 = this.TxtOperatorItem.Text;
			string text3 = "";
			string text4 = "";
			string shopImageUrl = "";
			string shopAdUrl = "";
			int shopIdentify = 0;
			string selectedText = this.ProvinceCity.SelectedText;
			if (text == string.Empty)
			{
				this.WriteErrMsg("", Language.Get("Shop/OpenShop/ShopNameNull"), "");
			}
			if (selectedText == string.Empty)
			{
				this.WriteErrMsg("", Language.Get("Shop/OpenShop/ProvinceCityNull"), "");
			}
			string selectedProvince = this.ProvinceCity.SelectedProvince;
			string selectedCity = this.ProvinceCity.SelectedCity;
			string area = "";
			string text5 = this.txtAddress.Text.ToString().Trim();
			if (text5 == string.Empty)
			{
				this.WriteErrMsg("", "店铺详细地址不能为空！", "");
			}
			if (this.ProvinceCity.SelectedArea != "")
			{
				area = this.ProvinceCity.SelectedArea;
			}
			text = Text.ReplaceBadChar(text);
			text4 = Text.ReplaceBadChar(text4);
			text3 = Text.ReplaceBadChar(text3);
			text2 = Text.ReplaceBadChar(text2);
			if (base.user.ShopID > 0 || this.conn.ExecuteCount("select shopid from hlshop_shop where  ShopOwnerID=" + base.user.UserID) > 0)
			{
				this.WriteErrMsg("", Language.Get("Shop/OpenShop/ShopExists"), "");
			}
			Shop_Shop shop_Shop = new Shop_Shop(this.conn);
			DataTable dataTable = null;
			if (base.user.CheckGroupPower("needcheck"))
			{
				shopIdentify = 1;
			}
			try
			{
				dataTable = shop_Shop.AddNewShop(base.user.UserID, text, shopAdUrl, text4, text3, num, shopImageUrl, shopIdentify, text2, base.user.UserName, text5, 1, base.Server.MapPath("..") + "/App_Data/CloseDate.xml", selectedProvince, selectedCity, area);
			}
			catch (Exception ex)
			{
				this.WriteErrMsg("", ex.Message.ToString(), "");
			}
			if (dataTable.Rows.Count > 0)
			{
				Shop_Class shop_Class = new Shop_Class(this.conn);
				shop_Class.UpdateItemCountByClassIDType(num, "addshop");
			}
			this.WriteSuccessMsg("", Language.Get("Shop/OpenShop/OpenShopSuccess"), "../Manage/shop_setup.aspx");
		}
	}
}
